package com.wuyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wuyou.entity.House;
import com.wuyou.mapper.HouseMapper;
import com.wuyou.service.IHouseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张钧程
 * @since 2022-09-30
 */
@Service
public class HouseServiceImpl extends ServiceImpl<HouseMapper, House> implements IHouseService {

    @Autowired
    private HouseMapper hm;

    @Override
    public Long saveReturnId(House house) {
        hm.insert(house);
        QueryWrapper<House> wrapper = new QueryWrapper<>();
        wrapper.eq("title",house.getTitle()).eq("host_id",house.getHostId()).eq("status",house.getStatus());
        List<House> houses = hm.selectList(wrapper);
        if (houses.isEmpty()){
            return null;
        }
        return houses.get(0).getHouseId();
    }
}
